using UnityEngine;

public class ArcherStunnedState : EnemyState
{
    private Archer archer => (Archer)Enemy;

    public ArcherStunnedState(Enemy enemy, string animName) : base(enemy, animName) { }

    public override void Enter()
    {
        base.Enter();
        if (archer.CounterImage.activeSelf)
        {
            archer.CloseCounterAttackWindow();
        }
        archer.Fx.InvokeRepeating("RedColorBlink", 0, 0.1f);
        stateTimer = archer.stunnedDuration;
        Rb.velocity = new Vector2(-archer.FacingDirection * archer.stunnedDirection.x, archer.stunnedDirection.y);
    }

    public override void Update()
    {
        base.Update();
        if (Rb.velocity.y < 0.1f && archer.IsGroundDetected())
        {
            archer.Fx.Invoke("CancelColorChange", 0);
            archer.Anim.SetTrigger("stunFold");
            archer.Stats.MakeInvincible(true);
        }
        if (stateTimer <= 0)
        {
            StateMachine.ChangeTo(archer.IdleState);
        }
    }

    public override void Exit()
    {
        base.Exit();
        archer.Stats.MakeInvincible(false);
    }
}
